package com.leorui.schoollife.mapper

import com.leorui.schoollife.entity.PersonalInfoResponse
import org.apache.ibatis.annotations.*

@Mapper
interface IDBPersonalInfo {
    // 获取个人信息
    @Select("select account, icon_id, icon_src, user_school.school_id, user_school.school_name, user_school.school_web_url, user_school.parse_type , power, area, nickname, sex, phone, student_id, personal_profile " +
            "from user_student left join user_icon on user_student.icon = user_icon.icon_id " +
            "left join user_school on user_student.school_id = user_school.school_id and account = #{account}")
    @Results(value = [
        Result(id = true, column = "account", property = "account"),
        Result(column = "icon_id", property = "icon.iconId"),
        Result(column = "icon_src", property = "icon.iconSrc"),
        Result(column = "school_id", property = "school.schoolId"),
        Result(column = "school_name", property = "school.schoolName"),
        Result(column = "school_web_url", property = "school.schoolWebUrl"),
        Result(column = "school_parse_type", property = "school.parseType"),
        Result(column = "power", property = "power"),
        Result(column = "area", property = "area"),
        Result(column = "nickname", property = "nickname"),
        Result(column = "sex", property = "sex"),
        Result(column = "phone", property = "phone"),
        Result(column = "student_id", property = "studentId"),
        Result(column = "personal_profile", property = "personalProfile"),
    ])
    fun getPersonalInfo(@Param(value = "account") account: String): PersonalInfoResponse?

    // 获取朋友圈个数
    @Select("select count(conversation_id) from circle_conversation_body where send_person_account = #{account}")
    fun getPersonalFriendCircleCount(@Param(value = "account") account: String): Int?

    // 更新个人信息
    @Update("update user_student " +
            "set personal_profile = #{personalProfile}, school_id = #{schoolId}, sex = #{sex}, area = #{area}, " +
            "icon = #{iconId}, nickname = #{nickname}, student_id = #{studentId}, phone = #{phone}" +
            "where account = #{account}")
    fun updatePersonalInfoStudent(
            @Param(value = "personalProfile") personalProfile: String,
            @Param(value = "schoolId") schoolId: Int,
            @Param(value = "sex") sex: Int,
            @Param(value = "area") area: String,
            @Param(value = "iconId") iconId: String,
            @Param(value = "nickname") nickname: String,
            @Param(value = "studentId") studentId: String,
            @Param(value = "phone") phone: String,
            @Param(value = "account") account: String,
    ): Int?

    // 更新教师信息
    @Update("update user_teacher set teach_course = #{teachClass} " +
            "where account = #{account} and teacher_id = #{teacherId}")
    fun updatePersonalInfoTeacher(
            @Param(value = "teachClass") teachClass: String,
            @Param(value = "account") account: String,
            @Param(value = "teacherId") teacherId: String,
    ): Int?

    // 更新管理员信息
    @Update("update user_administrator")
    fun updatePersonalInfoAdministrator(): Int?
}